//document.write(`<script src="${_js_dir_host}js/view/login/tools.js" type="text/javascript" charset="utf-8"></script>`);

define(["storage"], function(storage) {
	var getuiObj = {};
	/*
	 *绑定个推别名
	 * */
	getuiObj.OnBindUser = function(alias, successFun) {
		require(["request"], function(request) {
			var info = plus.push.getClientInfo();
			if(info.clientid.length > 0){
				request.OnAjax("post", "getui/bind", {
					client_id: info.clientid,
				},function(data){
					getuiObj.OnInit();
				});
			}
			console.log( "获取客户端推送标识信息：" );
			console.log("id: "+info.id);
			console.log( "token: "+info.token );
			console.log( "clientid: "+info.clientid );
			console.log( "appid: "+info.appid );
			console.log( "appkey: "+info.appkey );
		});
	}

	/*
	 *监听个推消息 
	 * */
	getuiObj.OnInit = function() {
		// 监听点击消息事件
		plus.push.addEventListener("click", function(msg) {
			// 判断是从本地创建还是离线推送的消息
			switch(msg.payload) {
				case "LocalMSG":
					plus.nativeUI.toast("点击本地创建消息启动：");
					break;
				default:
					plus.nativeUI.toast("点击离线推送消息启动：");
					break;
			}
			// 提示点击的内容
			plus.nativeUI.alert(msg.content);
		}, false);
		
		// 监听在线消息事件
		plus.push.addEventListener("receive", function(msg) {
			if(msg.aps) { // Apple APNS message
				plus.nativeUI.toast("接收到在线APNS消息：");
			} else {
				plus.nativeUI.toast("接收到在线透传消息：");
			}
			//提示点击的内容
			plus.nativeUI.alert(msg.content);
			//logoutPushMsg( msg );
		}, false);
	}
	
	
	//创建本地消息
	getuiObj.CreatLocalMsg = function(content){
		var options = {cover:false};
		plus.push.createMessage( content, "LocalMSG", options );
	}
	
	return getuiObj;
})